package org.cloud.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.HMac;

// 请使用ecc加密
//@Deprecated
public final class HashUtil {

    public final HMac hmacHash;
    private final String HMAC_KEY;
    private final String HMAC_SALT;

    private HashUtil() {
        String DEFAULT_HMAC_KEY = "tbq439UFFl6lCZpI";
        String HMAC_CONFIG_KEY = "system.hash.hmac.key";
        HMAC_KEY = EnvUtil.single().getEnv(HMAC_CONFIG_KEY, DEFAULT_HMAC_KEY);
        String DEFAULT_HMAC_SALT = "sd3vWRPElj5Tg4S5";
        String HMAC_CONFIG_SALT = "system.hash.hmac.salt";
        HMAC_SALT = EnvUtil.single().getEnv(HMAC_CONFIG_SALT, DEFAULT_HMAC_SALT);
        hmacHash = SecureUtil.hmacSha256(HMAC_KEY);
    }

    public String hmacHash(String str) {
        return hmacHash.digestHex(HMAC_SALT + str);
    }

    // 校验签名
    public boolean hmacHashVerify(String str, String signature) {
        return signature.equals(hmacHash(str));
    }


    public static final HashUtil HANDLER = new HashUtil();

}
